<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;

class Article extends Base {

    /*
     *
     * 文章主页
     * */
     public function index(){
         $this->isLogin();
         $res=Db::table('article')
             ->field('article.article_id,article.article_title,article.article_content,article.article_time,users.user_id,user_name')
             ->join('users','users.user_id = article.user_id')
             ->where("article_del=0")
             ->select();
         $this->assign('res',$res);

         return $this->fetch();
     }

     /*
      * 删除文章
      *
      * */
       public function delete(){
           $this->isLogin();
           $res=Request::instance()->get();
           $id=$res['id'];
           $res = Db::table('article')->where("article_id=$id")->update(['article_del'=>1]);
           if($res>0){
               echo 1;
           }else{
               echo 0;
           }
       }
     /*
      *
      * 文章详情页
      *
      * */
     public function details(){
         $this->isLogin();
              $res=Request::instance()->get();
              $id=$res['id'];
              $res=Db::table('article')
                 ->field('article.article_id,article.article_title,article.article_content,article.article_time,article.article_like,users.user_id,users.user_name')
                 ->join('users','users.user_id = article.user_id')
                 ->where("article_id=$id")
                 ->find();
             $this->assign('article_title',$res['article_title']);
             $this->assign('article_content',$res['article_content']);
             $this->assign('article_time',$res['article_time']);
             $this->assign('user_name',$res['user_name']);
             $this->assign('article_like',$res['article_like']);

         return $this->fetch();
     }

}